{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question 38\n",
    "\n",
    "### **Question:**\n",
    "\n",
    "> **_With a given tuple (1,2,3,4,5,6,7,8,9,10), write a program to print the first half values in one line and the last half values in one line._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints:\n",
    "\n",
    "> **_Use [n1:n2] notation to get a slice from a tuple._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tpl = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)\n",
    "\n",
    "for i in range(0, 5):\n",
    "    print(tpl[i], end=\" \")\n",
    "print()\n",
    "for i in range(5, 10):\n",
    "    print(tpl[i], end=\" \")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**OR**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tpl = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)\n",
    "lst1, lst2 = [], []\n",
    "\n",
    "for i in range(0, 5):\n",
    "    lst1.append(tpl[i])\n",
    "\n",
    "for i in range(5, 10):\n",
    "    lst2.append(tpl[i])\n",
    "\n",
    "print(lst1)\n",
    "print(lst2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**OR**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "Solution by: CoffeeBrakeInc\n",
    "\"\"\"\n",
    "\n",
    "tup = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)\n",
    "lt = int(len(tup) / 2)\n",
    "print(tup[:lt], tup[lt:])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "**OR**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "Solution by: AasaiAlangaram\n",
    "\"\"\"\n",
    "\n",
    "tp = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)\n",
    "\n",
    "print(\"The Original Tuple:\", tp)\n",
    "\n",
    "[\n",
    "    print(\"Splitted List :{List}\".format(List=tp[x : x + 5]))\n",
    "    for x in range(0, len(tp), 5)\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 39\n",
    "\n",
    "### **Question:**\n",
    "\n",
    "> **_Write a program to generate and print another tuple whose values are even numbers in the given tuple (1,2,3,4,5,6,7,8,9,10)._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints:\n",
    "\n",
    "> **_Use \"for\" to iterate the tuple. Use tuple() to generate a tuple from a list._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tpl = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)\n",
    "tpl1 = tuple(i for i in tpl if i % 2 == 0)\n",
    "print(tpl1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**OR**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tpl = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)\n",
    "tpl1 = tuple(\n",
    "    filter(lambda x: x % 2 == 0, tpl)\n",
    ")  # Lambda function returns True if found even element.\n",
    "# Filter removes data for which function returns False\n",
    "print(tpl1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 40\n",
    "\n",
    "### **Question:**\n",
    "\n",
    "> **_Write a program which accepts a string as input to print \"Yes\" if the string is \"yes\" or \"YES\" or \"Yes\", otherwise print \"No\"._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints:\n",
    "\n",
    "> **_Use if statement to judge condition._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solution: Python 3**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "Solution by: Seawolf159\n",
    "\"\"\"\n",
    "text = input(\"Please type something. --> \")\n",
    "if text == \"yes\" or text == \"YES\" or text == \"Yes\":\n",
    "    print(\"Yes\")\n",
    "else:\n",
    "    print(\"No\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "Solution by: AasaiAlangaram\n",
    "\"\"\"\n",
    "input = input(\"Enter string:\")\n",
    "output = \"\".join(\n",
    "    [\"Yes\" if input == \"yes\" or input == \"YES\" or input == \"Yes\" else \"No\"]\n",
    ")\n",
    "print(str(output))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 41\n",
    "\n",
    "### **Question:**\n",
    "\n",
    "> **_Write a program which can map() to make a list whose elements are square of elements in [1,2,3,4,5,6,7,8,9,10]._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints:\n",
    "\n",
    "> **_Use map() to generate a list.Use lambda to define anonymous functions._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# No different way of code is written as the requirment is specificly mentioned in problem description\n",
    "\n",
    "li = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n",
    "squaredNumbers = map(lambda x: x ** 2, li)  # returns map type object data\n",
    "print(list(squaredNumbers))  # converting the object into list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 42\n",
    "\n",
    "### **Question:**\n",
    "\n",
    "> **_Write a program which can map() and filter() to make a list whose elements are square of even number in [1,2,3,4,5,6,7,8,9,10]._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints:\n",
    "\n",
    "> **_Use map() to generate a list.Use filter() to filter elements of a list.Use lambda to define anonymous functions._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def even(x):\n",
    "    return x % 2 == 0\n",
    "\n",
    "\n",
    "def squer(x):\n",
    "    return x * x\n",
    "\n",
    "\n",
    "li = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n",
    "li = map(\n",
    "    squer, filter(even, li)\n",
    ")  # first filters number by even number and the apply map() on the resultant elements\n",
    "print(list(li))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 43\n",
    "\n",
    "### **Question:**\n",
    "\n",
    "> **_Write a program which can filter() to make a list whose elements are even number between 1 and 20 (both included)._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints:\n",
    "\n",
    "> **_Use filter() to filter elements of a list.Use lambda to define anonymous functions._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def even(x):\n",
    "    return x % 2 == 0\n",
    "\n",
    "\n",
    "evenNumbers = filter(even, range(1, 21))\n",
    "print(list(evenNumbers))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
